﻿namespace LoveMusic
{
    using System.Web.Mvc;
    using System.Collections.Generic;
    using LoveMusic.Models;

    public class StartController : BaseController
    {
        #region private

        private readonly IDataContext _dataContext;

        private IDataContext DataContext
        {
            [System.Diagnostics.DebuggerStepThrough]
            get
            {
                return _dataContext;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SongController"/> class.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="userManager">The membership provider that will be used.</param>
        public StartController(IDataContext dataContext)
        {
            _dataContext = dataContext;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SongController"/> class.
        /// </summary>
        public StartController()
            : this(new ModelDataContext())
        {
        }


        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        [NonAction]
        public void Dispose()
        {
            if (_dataContext != null)
            {
                _dataContext.Dispose();
            }
        }

        #endregion

        [CompressFilter]
        [OutputCache(Duration = int.MaxValue, VaryByParam = "none")]
        public ActionResult Index()
        {
            var viewData = GetViewData<StartDetailData>();
            return View("Index", viewData);
        }


        private T GetViewData<T>() where T : BaseViewData, new()
        {
            var viewData = new T
            {
                AllMoods = DataContext.AllMoods(),
                RandArtists = DataContext.Get50Artist(),
                RandSong = DataContext.Get50Songs()
            };

            return viewData;
        }

    }
}
